package com.bdqn.qnnews.articel.api.fallback;

import com.bdqn.qnnews.articel.api.dto.ApArticleDto;
import com.bdqn.qnnews.articel.api.dto.ApAuthorDto;
import com.bdqn.qnnews.articel.api.feign.ArticleFeignClient;
import com.bdqn.qnnews.common.base.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 服务降级的处理方式
 * @author xlzhang
 */
@Slf4j
@Component
public class ApArticleAuthorFeignFallback implements FallbackFactory<ArticleFeignClient> {

    @Override
    public ArticleFeignClient create(Throwable e) {
        return new ArticleFeignClient() {
            @Override
            public R<List<ApArticleDto>> findAllArticles() {
                log.error("查询所有文章信息 远程调用出错啦 ~~~ !!!! {}",e.getMessage());
                throw new RuntimeException("查询所有文章信息 远程调用出错啦 ~~~ !!!! " + e.getMessage());
            }

            @Override
            public R<Long> saveAndUpdate(ApArticleDto dto) {
                log.error("参数: {}",dto);
                log.error("保存和更新文章信息 远程调用出错啦 ~~~ !!!! {}",e.getMessage());
                throw new RuntimeException("保存和更新文章信息 远程调用出错啦 ~~~ !!!! " + e.getMessage());
            }

            @Override
            public R<ApAuthorDto> getByApUserId(Long userId) {
                log.error("参数: {}",userId);
                log.error("查询文章作者信息 远程调用出错啦 ~~~ !!!! {}",e.getMessage());
                throw new RuntimeException("查询文章作者信息 远程调用出错啦 ~~~ !!!! " + e.getMessage());
            }

            @Override
            public R<String> save(ApAuthorDto apAuthorDto) {
                log.error("参数: {}",apAuthorDto);
                log.error("保存文章作息信息 远程调用出错啦 ~~~ !!!! {} ",e.getMessage());
                throw new RuntimeException("保存文章作息信息 远程调用出错啦 ~~~ !!!! " + e.getMessage());
            }
        };
    }
}